<?php

namespace App\Traits;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;

trait BaseModelTrait
{
    /**
     * Desc scopeId
     * @param $query
     * @param int|null $id
     * @return Builder
     */
    public function scopeId($query, int|null $id = 0): Builder
    {
        return $query->where($this->getTable() . '.id', $id);
    }

    /**
     * Desc serializeDate
     * @param DateTimeInterface $date
     * @return string
     */
    public function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }
}
